package IO;

import java.io.*;

/**
 * 文件输入输出流达到文件的拷贝
 */
public class Copy_Buffered {
    public static void copy(String srcPath,String destPath){
        //创建源
        File src = new File(srcPath);//源头
        File dest = new File(destPath);//目的地
        //选择流

        //读取
        try (InputStream input = new BufferedInputStream(new FileInputStream(src)) ;
                OutputStream out = new BufferedOutputStream(new FileOutputStream(dest)) ){
            byte[] flush = new byte[1024];
            int len;
            while ((len = input.read(flush))!=-1){
                String str = new String(flush,0,len);
                byte[] datas = str.getBytes();
                out.write(datas,0,datas.length);
                out.flush();
            }
            //先打开的后关闭
            out.close();
            input.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        copy("src/IO/abc.txt","src/IO/dest.txt");
    }
}
